<?php
$driver=null;
include_once("testheader.php");
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverExpectedCondition;
use Facebook\WebDriver\WebDriverWait;

$url="https://channels.weixin.qq.com/shop/goods/entry?productId=10000143263336&isUpdateAuditFree=0&source=list_edit";
$driver->get($url);
$host=host($url);
$wwwhost=wwwhost($url);
$cookieString = getone("select cookie from longzs.longzs_cookies where host='{$wwwhost}'");
if($cookieString=="") {
    $cookieString = getone("select cookie from longzs.longzs_re where host='{$host}'");
}
$cookies = explode(';', $cookieString);
foreach ($cookies as $cookiePart) {
    $cookieKeyValue = explode('=', $cookiePart);
    if (count($cookieKeyValue) == 2) {
        $cookieName = trim($cookieKeyValue[0]);
        $cookieValue = trim($cookieKeyValue[1]);
        $driver->manage()->addCookie(array(
            'name' => $cookieName,
            'value' => $cookieValue,
            'domain' => ".{$wwwhost}",  // 设置正确的域名
            'path' => '/',
        ));
    }
}
$driver->get($url);
//$wait = new WebDriverWait($driver, 5);
//$element = $wait->until(
//    WebDriverExpectedCondition::visibilityOfElementLocated(
//        WebDriverBy::cssSelector(".weui-desktop-form__input")
//    )
//);
//$driver->getPageSource();

// 获取影子根元素
$script = "return document.querySelector('#app > div > div.app_content > div:nth-child(4) > micro-app').shadowRoot";
$shadowRoot = $driver->executeScript($script);

// 获取影子根的 pageSource
$pageSource = $driver->executeScript('return arguments[0].outerHTML', [$shadowRoot]);
$wait = new WebDriverWait($driver, 555);
